#region imported Namespaces
using System;
using System.Data;
using BO = PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
#endregion

namespace PHSRAG.Insight21.Purchasing
{
	/// <summary>
	/// The JournalEntryDetail class is the facade over the details for a single personnel summary.
	/// </summary>
	public class JournalEntryDetail: BO.BusinessObject
	{
		#region Constants
		private const string JournalEntryDetailKey		= "JournalEntryDetailKey_270215c3-7fb3-424d-8500-0605793ca551";
		private const string JournalIdColName			= "JournalID";
		private const string DescriptionColName			= "Description";
		private const string FundNumberColName			= "FundNumber";
		private const string AccountNumberColName		= "AccountNumber";
		private const string AccountDescriptionColName	= "AccountDescription";
		private const string AmountColName				= "Amount";
		private const string PostedByColName			= "PostedBy";

		#endregion

		#region Instance variables
		private DataRow summaryRow;
		#endregion

		#region Public Properties

			
		/// <summary>
		///  Displays the PeopleSoft Fund # assocated with Journal Entries ,  
		/// </summary>
		public string FundNumber
		{
			get
			{
				object o = summaryRow[FundNumberColName];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}		
		/// <summary>
		/// Displays the Account # assocated with Journal entry.
		/// </summary>
		public string AccountNumber
		{
			get
			{
				object o = summaryRow[AccountNumberColName];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Displays the Account Description assocated with Journal entry.
		/// </summary>
		public string AccountDescription
		{
			get
			{
				object o = summaryRow[AccountDescriptionColName];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}
			
		/// <summary>
		/// Displays the Journal ID 
		/// </summary>
		public string JournalID
		{
			get
			{
				object o = summaryRow[JournalIdColName];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}
				
		/// <summary>
		/// Displays the Description of the transaction.
		/// </summary>
		public string Description
		{
			get
			{
				object o = summaryRow[DescriptionColName];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}
		/// <summary>
		/// Rolled up  amount for an Journal Entry
		/// </summary>
		public decimal Amount
		{
			get
			{
				object o = summaryRow[AmountColName];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}
			
		/// <summary>
		/// Journal Entry Posted date
		/// </summary>
		public string PostedBy
		{			
			get
			{
				object o = summaryRow[PostedByColName];
				return (o == DBNull.Value) ? "" : ((DateTime)o).ToString("MM/dd/yyyy");
			}
		}
		
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the base class with the specified cache policy and assign the DataRow to the instance variable
		/// </summary>
		/// <param name="cachePolicy">Prevalent cache policy</param>
		/// <param name="dataRow">DataRow containing personnel summary data</param>
		public JournalEntryDetail(ICachePolicy cachePolicy,DataRow dataRow) : base (cachePolicy)
		{
			summaryRow = dataRow;
		}
		
	#endregion

		#region BusinessObject Methods
		/// <summary>
		/// Cache the JournalEntry instance using the prevalent cache policy
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(JournalEntryDetailKey,this);
		}
		/// <summary>
		/// Remove the JournalEntry instance from the cache using the prevalent cache policy
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(JournalEntryDetailKey);
		}
		/// <summary>
		/// This method is not used and only exists to satisfy interface requirements.
		/// </summary>
		public override void Load(string connectionString, params object[] args)
		{			
			throw new Exception("JournalEntry cannot be directly loaded.");
		}
		#endregion

		

	}
}
